Instrumentation is a technique that can enable engineers to comprehend, monitor, and assess the operation of software. Typically, a program is instrumented by inserting probes at various points in the program, where the probes report a variety of information such as whether certain portions of a program have been reached (referred to as coverage), the number of times that various portions of the program have been executed (referred to as execution counts), how much time is spent in various portions of the program, and so forth. Instrumentation thus facilitates the identification of coverage efficiency, bottlenecks, bugs, and other deficiencies in a program and, consequently, can aid in the process of improving the quality, security, efficiency, and performance of programs.
The introduction of probes into a program, however, adds overhead that can slow down the execution of the program, and thus there is a tradeoff when inserting probes into a program. Ideally, the probes should cover all of the various execution paths of the program, and should be sufficient in number so that the reported information is fine-grained enough to be useful. However, if there are too many probes, then program runtime performance might suffer appreciably, which is unacceptable in applications such as real-time embedded systems and Voice over Internet Protocol (VoIP).
Typically methods for determining probe insertion points in a program are based on a control-flow graph that is derived from the program. FIG. 1 depicts illustrative program 100, and FIG. 2 depicts control-flow graph 200 corresponding to program 100, both in accordance with the prior art. As shown in FIG. 2, control-flow graph 200 comprises nodes 201-1 through node 201-13, connected by arcs as shown. For convenience, each node of control-flow graph 200 has been assigned a label that indicates the portion of program 100 (known as a basic block) to which it corresponds.
In one method of the prior art, known as a maximum spanning tree method, arcs are first added to the control-flow graph, as necessary, so that at each node, the incoming execution count equals the outgoing execution count. Weights are then assigned to the arcs of the (possibly-augmented) control-flow graph, and a maximum spanning tree is generated (i.e., a spanning tree such that the sum of its arc weights is maximum.) Finally, a probe is inserted at every node in the control-flow graph that leads to an arc not in the spanning tree.
FIG. 3 depicts an illustrative maximum spanning tree for control-flow graph 200, indicated by boldface arcs, in accordance with the prior art. (For simplicity, weights are not depicted in the figure.) As shown in FIG. 3, an arc from node 201-13 to node 201-1 has been added to ensure that the incoming and outgoing execution counts are equal at each node.
It is readily apparent from FIG. 3 that the following arcs are not part of the spanning tree:                (201-6, 201-8) [B-E6],        (201-9, 201-11) [D-E6E]        (201-4, 201-12) [F-E1E]        (201-12, 201-2) [E1E-E1]        (201-2, 201-13) [E1-G]Consequently, probes are inserted in nodes B, D, F, E1E, and E1.        
A key disadvantage of the maximum spanning tree method is that it requires execution counts on each probe, which can consume a great deal of memory. Moreover, the counter values can grow so large that they impact the original application, and there is no way to reset the counters. Consequently, the maximum spanning tree method is typically not practical for program monitoring during field operation.
In another method of the prior art, known as a super block dominator method, a pre-dominator tree of the control-flow graph is first generated—i.e., a tree in which a first node is an ancestor of a second node if and only if the first node is guaranteed to execute before the second node. FIG. 4 depicts pre-dominator tree 400 for control-flow graph 200, in accordance with the prior art.
Next, a post-dominator tree of the control-flow graph is generated—i.e., a tree in which a first node is a descendent of a second node if and only if the first node is guaranteed to execute before the second node. FIG. 5 depicts post-dominator tree 500 for control-flow graph 200, in accordance with the prior art.
The pre-dominator and post-dominator trees are then combined into a single dominator graph. FIG. 6 depicts dominator graph 600 for control-flow graph 200, in accordance with the prior art. Dominator graph 600 is simply the union of pre-dominator tree 400 and post-dominator tree 500, and can be obtained by adding the arcs of post-dominator tree 500 to pre-dominator tree 400.
Next, the strongly-connected components of the dominator graph are determined. A strongly-connected component is a maximal set of nodes in a directed graph such that every node in the set is reachable from every other node in the set. FIG. 7 depicts the strongly-connected components of dominator graph 600, in accordance with the prior art.
Finally, each strongly-connected component is defined as a respective super block, and a probe is inserted in each of the super blocks. In this example, a probe is inserted into each of the following super blocks of program 100: {A, E1, G}, {E2, E1E}, {F}, {E3, E6, E6E}, {B}, {C}, {D}, and {E}.